import("//llvm/tools/binutils_symlinks.gni")
import("//llvm/utils/TableGen/tablegen.gni")
import("//llvm/utils/gn/build/symlink_or_copy.gni")

tablegen("ObjdumpOpts") {
  visibility = [ ":llvm-objdump" ]
  args = [ "-gen-opt-parser-defs" ]
}

tablegen("OtoolOpts") {
  visibility = [ ":llvm-objdump" ]
  args = [ "-gen-opt-parser-defs" ]
}

symlinks = [ "llvm-otool" ]
if (llvm_install_binutils_symlinks) {
  symlinks += [ "objdump" ]
}

foreach(target, symlinks) {
  symlink_or_copy(target) {
    deps = [ ":llvm-objdump" ]
    source = "llvm-objdump"
    output = "$root_out_dir/bin/$target"
  }
}

# //:llvm-objdump depends on this symlink target, see comment in //BUILD.gn.
group("symlinks") {
  deps = [ ":llvm-objdump" ]
  foreach(target, symlinks) {
    deps += [ ":$target" ]
  }
}

executable("llvm-objdump") {
  deps = [
    ":ObjdumpOpts",
    ":OtoolOpts",
    "//llvm/include/llvm/Config:config",
    "//llvm/lib/CodeGen",
    "//llvm/lib/DebugInfo/DWARF",
    "//llvm/lib/DebugInfo/PDB",
    "//llvm/lib/DebugInfo/Symbolize",
    "//llvm/lib/Demangle",
    "//llvm/lib/MC",
    "//llvm/lib/MC/MCDisassembler",
    "//llvm/lib/Object",
    "//llvm/lib/Option",
    "//llvm/lib/Support",
    "//llvm/lib/Target:AllTargetsDescs",
    "//llvm/lib/Target:AllTargetsDisassemblers",
    "//llvm/lib/Target:AllTargetsInfos",
    "//llvm/utils/gn/build/libs/xar",
  ]
  sources = [
    "COFFDump.cpp",
    "ELFDump.cpp",
    "MachODump.cpp",
    "SourcePrinter.cpp",
    "WasmDump.cpp",
    "XCOFFDump.cpp",
    "llvm-objdump.cpp",
  ]
}
